import json
import os

from websocket import create_connection

ws = create_connection("ws://118.89.35.209:19999/ws/job/d8709d92-bd4b-4b1b-927b-442d953d9292")
# ws = create_connection("ws://127.0.0.1:9999/ws/job/d8709d92-bd4b-4b1b-927b-442d953d9292")
ws.send('连接成功')
flag = True

UIPATH_TRIGER_CMD = r"C:\Users\Paton\AppData\Local\UiPath\app-20.6.0-beta0093\UiRobot.exe -file %s"

while flag:
    result = ws.recv()
    result = json.loads(result)

    if result.get('message') != "连接成功":
        data_dict = json.loads(result.get('message'))
        script_path = data_dict.get('path')
        script_path = script_path.replace("\\u202a",'').replace('?','')
        cmd = UIPATH_TRIGER_CMD % script_path
        # cmd = r'C:\Users\肥仔锋丶\AppData\Local\UiPath\app-20.6.0-beta0093\UiRobot.exe -file G:\Uipath\stock_demo\Main.xaml'
        print(cmd)
        cmd_res = os.popen(cmd)
        print(cmd_res)



ws.close()


